home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 29 / applic / 3dfile.txt next >
Text File  |  1985-11-19  |  7KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.                          CAD-3D .3D Object File Format
  9.  
  10.                                  by Tom Hudson
  11.  
  12.  
  13.  
  14.     The CAD-3D solid modeling system uses a fairly straightforward file
  15.     format to store user-defined 3-Dimensional objects.  Each .3D file can
  16.     contain up to 20 objects, but it is suggested that for files that are
  17.     intended to be merged with existing groups of objects, the number of
  18.     objects should be kept below 10.
  19.  
  20.  
  21.                                   File Header
  22.                                   -----------
  23.  
  24.     The first 34 bytes of each .3D file is a header specifying the number
  25.     of 3-D objects in the file and direct light source information, as
  26.     follows:
  27.  
  28.     Bytes 1-2:  A WORD value containing the hex value $3D3D.  This is a
  29.     "magic number" which may be tested to be sure the file is a 3D object
  30.     file.
  31.  
  32.     Bytes 3-4:  A WORD value which tells how many 3D objects are contained
  33.     in the file.  Must range from 1-20.  We will refer to this value as
  34.     OBCOUNT.
  35.  
  36.     Bytes 5-10:  Three WORD values which specify the brightness of the
  37.     three direct light sources.  These values must range from 0-7.  The
  38.     first WORD value is the brightness of light source A, the second is the
  39.     brightness of light source B, and the third is for light source C.
  40.  
  41.     Bytes 11-16:  Three WORD values specifying whether each of the three
  42.     light sources are ON or OFF.  A value of 0 means the light source is
  43.     OFF, a value of 1 means the source is ON.  These three words are in
  44.     light source A, B, C order, as is all the light source-related
  45.     information.
  46.  
  47.     Bytes 17-22:  Three WORD values specifying the vertical position of the
  48.     light sources A, B and C.  A value of 0 indicates the light is from the
  49.     TOP, 1 indicates that the light is from the CENTER, and 2 indicates the
  50.     light source is from the TOP.  Again, these words are in A-B-C order.
  51.  
  52.     Bytes 23-28:  Three WORD values specifying the front-back position of
  53.     the light sources.  0 indicates the source is positioned at the FRONT,
  54.     1 indicates the CENTER, and 2 indicates the BACK position.  Also in
  55.     source A-B-C order.
  56.  
  57.     Bytes 29-34:  Three WORD values specifying the left-right position of
  58.     the light sources.  0 indicates the source is to the LEFT, 1 indicates
  59.     the source is at the CENTER, 2 indicates the RIGHT position.  Also in
  60.     source A-B-C order.
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.                                 3-D Object Data
  75.                                 ---------------
  76.  
  77.     The remainder of the file is made up of variable-sized blocks of data
  78.     which describe each 3-D object in the file.  The OBCOUNT WORD in the
  79.     file header tells how many objects are in the file.  Read one of these
  80.     3-D data blocks for each object in the file.
  81.  
  82.     9 bytes:  Object name.  This is a simple string of up to eight bytes
  83.     plus a terminating $00 byte which is the name of the object as used by
  84.     CAD-3D.  Names must be unique within the file, and if they are merged
  85.     into RAM with objects of the same name, the user must re-enter the
  86.     object name.  Any characters may be used for this string, but
  87.     meaningful names that describe the object, such as CUBE, JET, etc. are
  88.     best.
  89.  
  90.     2 bytes:  A WORD specifying the number of vertices in the object.  May
  91.     not exceed 15000.  We will refer to this value as VCOUNT.
  92.  
  93.     VCOUNT * 4 bytes:  An array of X-coordinate values for the object.
  94.     These values must be in the range -45 to +45 for CAD-3D to process
  95.     them.  In the CAD-3D universe, negative X values are toward the left,
  96.     positive X values are toward the right.  This is a floating-point array
  97.     stored in the Motorola Fast Floating-Point (LIBF) format, in which each
  98.     value is four bytes in length.  For easiest processing, simply read
  99.     this block of data directly into a FLOAT array of sufficient size.
  100.  
  101.     VCOUNT * 4 bytes:  An array of Y-coordinate values for the object.
  102.     Range from -45 to +45.  Negative Y values are toward the front,
  103.     positive Y values are toward the back.  Like the X coordinate array,
  104.     each coordinate is in LIBF format, four bytes per value.
  105.  
  106.     VCOUNT * 4 bytes:  An array of Z-coordinate values for the object.
  107.     Range from -45 to +45.  Negative Z values are toward the bottom,
  108.     positive Y values are toward the top of the CAD-3D universe.  Also in
  109.     LIBF floating-point format.
  110.  
  111.     2 bytes:  A WORD specifying the number of faces in the 3-D object.  In
  112.     CAD-3D, each face is a triangle specified by three vertices, always
  113.     given in a counter-clockwise order A-B-C as viewed from the outside of
  114.     the object.  We will refer to this value as FCOUNT.
  115.  
  116.     The following 8 bytes make up a structure which is repeated FCOUNT
  117.     times, one entry for each face.
  118.  
  119.     2 bytes:  A WORD specifying the number of vertex A, the first point in
  120.     the face.  Must be 0<=vertex A<VCOUNT.
  121.  
  122.     2 bytes:  A WORD specifying the number of vertex B, the second point of
  123.     the face.  Must be 0<=vertex B<VCOUNT.
  124.  
  125.     2 bytes:  A WORD specifying the number of vertex C, the third point of
  126.     the face.  Must be 0<=vertex C<VCOUNT.
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.     2 bytes:  A WORD specifying the color of the face and whether or not
  140.     the line segments of the face are edges.
  141.  
  142.              Bits 0-3:  Color of the face.  COLOR 1 is 1-7 (where
  143.                         1 is low brightness and 7 is high brightness),
  144.                         COLOR 2 is 8-14 (8 is brightness 1, 14 is
  145.                         brightness 7 for color 2).
  146.  
  147.              Bit 4:  Indicates whether or not the line segment from
  148.                      vertex C to vertex A is an edge.  0=not edge,
  149.                      1=edge.  Used for ALL LINES/EDGES ONLY modes.
  150.  
  151.              Bit 5:  Indicates whether or not the line segment from
  152.                      vertex B to vertex C is an edge.
  153.  
  154.              Bit 6:  Indicates whether or not the line segment from
  155.                      vertex A to vertex B is an edge.
  156.  
  157.  
  158.     Once the face structure has been read FCOUNT times and processed, you
  159.     are ready to begin the process of reading the next 3-D object in the
  160.     file, if one exists.  If it does, the next information in the file will
  161.     be the 9-character name of the next object.  If not, you can close the
  162.     file.
  163.  
  164.  
  165.                                   Final words
  166.                                   -----------
  167.  
  168.     If you have any questions about the CAD-3D file format, please contact
  169.     Tom Hudson [76703,4224].
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199. əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə